using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using IGlobalist.Cms.Model;
using Ader.TemplateEngine;

namespace IGlobalist.Cms.Presentation
{
    public class AderTemplateEngine : ITemplateEngine
    {
        private ITemplate _Template;
        private TemplateManager _Engine;
        public AderTemplateEngine(ITemplate template)
        {
            if (template.Type != TemplateType.Ader)
                throw new Exception("[Ader] Template type not match.");
            this._Engine = TemplateManager.FromString(template.TemplateContent);
            this._Template = template;
        }


        #region ITemplateEngine Members

        public ITemplate Template
        {
            get
            {
                return this._Template;
            }
        }

        public void AddToContext(string key, object obj)
        {
            this._Engine.SetValue(key, obj);
        }

        public void Render(System.IO.TextWriter output)
        {
            this._Engine.Process(output);
        }
        #endregion
    }
}
